package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author zhaoxw
 * @description TODO
 * @date 2024/2/5 15:49
 */
@RestController
@Slf4j
@Api(tags = "菜品管理接口")
@RequestMapping("/admin/dish")
public class DishController {


    @Autowired
    private DishService dishService;

    @ApiOperation("新增菜品")
    @PostMapping("save")
    public Result save(@RequestBody DishDTO dishDTO) {
        dishService.save(dishDTO);
        return Result.success();
    }

    @ApiOperation("分页查询")
    @GetMapping("page")
    public Result page(DishPageQueryDTO dishPageQueryDTO) {
        PageResult<DishVO> page = dishService.page(dishPageQueryDTO);
        return Result.success(page);

    }

    @ApiOperation("删除菜品")
    @GetMapping("delByIds")
    public Result delDishByIds(@RequestParam List<Long> ids) {
        dishService.delByIds(ids);
        return Result.success();
    }

    @ApiOperation("根据id查询菜品")
    @GetMapping("queryById/{id}")
    public Result<DishVO> queryById(@PathVariable Long id) {
        DishVO dishVO = dishService.queryById(id);
        return Result.success(dishVO);
    }

    @ApiOperation("根据id查询菜品z")
    @GetMapping("queryByIdz/{id}")
    public Result<DishVO> queryByIdz(@PathVariable long id) {
        DishVO dishVO = dishService.queryByIdz(id);
        return Result.success(dishVO);

    }


    @ApiOperation("修改菜品")
    @PostMapping("updateWithFlavor")
    public Result updateWithFlavor(@RequestBody DishVO dishVO) {
        dishService.updateWithFlavor(dishVO);
        return Result.success();
    }


}
